/*
**==============================================================================
**
** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE
** for license information.
**
**==============================================================================
*/

#include "lock.h"
#include <pthread.h>
#include <unistd.h>
#include <errno.h>

/*
**==============================================================================
**
** Local definitions:
**
**==============================================================================
*/

#define CONDLOCKENTRY_INITIALIZER \
    { PTHREAD_COND_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, 0, 0, 0 }

typedef struct _CondLockSlot
{
    /* Condition variable */
    pthread_cond_t cond;

    /* Mutex used to synchronize the condition */
    pthread_mutex_t mutex;

    /* The key of the last waiter for this slot */
    ptrdiff_t key;

    /* Number of threads waiting on this condition */
    size_t waiters;

    /* Non-zero if there has been a collision */
    unsigned int collision;
}
CondLockSlot;

#if defined(CONFIG_FAVORSIZE)
# define CONDLOCK_NUMSLOTS 16
#else
# define CONDLOCK_NUMSLOTS 1024
#endif

static CondLockSlot _slots[CONDLOCK_NUMSLOTS] =
{
#if defined(CONFIG_FAVORSIZE)
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER
#else /* defined(CONFIG_FAVORSIZE) */
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER,
    CONDLOCKENTRY_INITIALIZER
#endif /* defined(CONFIG_FAVORSIZE) */
};

static unsigned int _initialized = 0;
static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;

static void _AtForkHelper(unsigned int lock)
{
    size_t i;

    for (i = 0; i < CONDLOCK_NUMSLOTS; i++)
    {
        if (lock)
            pthread_mutex_lock(&_slots[i].mutex);
        else
            pthread_mutex_unlock(&_slots[i].mutex);
    }

    if (lock)
        pthread_mutex_lock(&_mutex);
    else
        pthread_mutex_unlock(&_mutex);
}

static void _AtForkPrepare()
{
    /* Lock */
    _AtForkHelper(1);
}

static void _AtForkParent()
{
    /* Unlock */
    _AtForkHelper(0);
}

static void _AtForkChild()
{
    _initialized = 0;
    /* Unlock */
    _AtForkHelper(0);
}

static void _Initialize()
{
    pthread_mutex_lock(&_mutex);

    if (_initialized == 0)
    {
        pthread_atfork(_AtForkPrepare, _AtForkParent, _AtForkChild);
        _initialized = 1;
    }

    pthread_mutex_unlock(&_mutex);
}

PAL_INLINE CondLockSlot* _GetSlot(ptrdiff_t x)
{
    size_t i = (x ^ (x >> 3) ^ (x >> 12) ^ (x >> 22)) % CONDLOCK_NUMSLOTS;
    return &_slots[i];
}

/*
**==============================================================================
**
** Public definitions:
**
**==============================================================================
*/

int CondLock_Wait(
    ptrdiff_t key,
    _In_ volatile const ptrdiff_t* destination,
    ptrdiff_t comparand,
    size_t spinCount)
{
    CondLockSlot* slot;

    if (_initialized == 0)
        _Initialize();

    /* Get the slot for this key */
    slot = _GetSlot(key);

    /* Lock the entry */
    pthread_mutex_lock(&slot->mutex);

    /* Is the condition already satisfied? */
    if (*destination != comparand)
    {
        pthread_mutex_unlock(&slot->mutex);
        return 1;
    }

    /* Update the state of this slot */
    {
        if (slot->waiters > 0 && slot->key != key)
            slot->collision = 1;

        slot->key = key;
        slot->waiters++;
    }

    /* Wait (unlocks mutex on entry and relocks it on exit) */
    pthread_cond_wait(&slot->cond, &slot->mutex);

    /* Decrement number of waiters */
    slot->waiters--;

    /* If the number of waiters is zero, clear the collision state */
    if (slot->waiters == 0)
        slot->collision = 0;

    /* Unlock the mutex */
    pthread_mutex_unlock(&slot->mutex);

    /* Return 1 if condition is satisfied (or 0 otherwise) */
    return *destination == comparand ? 0 : 1;
}

void CondLock_Broadcast(
    ptrdiff_t key)
{
    CondLockSlot* slot;

    if (_initialized == 0)
        _Initialize();

    slot = _GetSlot(key);
    pthread_mutex_lock(&slot->mutex);
    pthread_cond_broadcast(&slot->cond);
    pthread_mutex_unlock(&slot->mutex);
}

void CondLock_Signal(
    ptrdiff_t key)
{
    CondLockSlot* slot;

    if (_initialized == 0)
        _Initialize();

    slot = _GetSlot(key);
    pthread_mutex_lock(&slot->mutex);

    if (slot->collision)
    {
        /* There are collisions, so wake up all waiters */
        pthread_cond_broadcast(&slot->cond);
    }
    else
    {
        /* There no collisions, so wake up next waiter in line */
        pthread_cond_signal(&slot->cond);
    }

    pthread_mutex_unlock(&slot->mutex);
}
